import 'package:flutter/cupertino.dart';
import 'package:sp_util/sp_util.dart';

const _KProxyEnable = "com.zh.proxyEnable";
const _KProxyIp = "com.zh.proxyip";
const _KProxyPort = "com.zh.proxyport";
const _KDomain = "com.zh.domain";

const bool _inProduction = const bool.fromEnvironment("dart.vm.product");

class HBHttpConfig {
  factory HBHttpConfig() =>_getInstance();
  static HBHttpConfig get instance => _getInstance();
  static HBHttpConfig _instance;

  List<String> _devDomains = [
  ];

  List<String> get allDomains {
    return [_onlineDomain] + _devDomains;
  }

  String _onlineDomain;

  static configDomains({@required String online, List<String> others}) {
    HBHttpConfig.instance._onlineDomain = online;
    HBHttpConfig.instance._devDomains = others ?? [];
  }

  static HBHttpConfig _getInstance() {
    if (_instance == null) {
      _instance = new HBHttpConfig._internal();
    }
    return _instance;
  }

  HBHttpConfig._internal() {
    // defaultConfig();
  }

  // defaultConfig() {
  //   // 初始化
  // }

  bool get proxyEnable {
    if (_inProduction == true) return false;
    final v = SpUtil.getBool(_KProxyEnable);
    if (v != true) return false;
    return true;
  }

  String get domain {
    if (_inProduction == true) return _onlineDomain;
    final v = SpUtil.getString(_KDomain);
    if (v?.isNotEmpty == true) {
      return v;
    } else {
      return _onlineDomain;
    }
  }

  String get proxy_ip {
    final v = SpUtil.getString(_KProxyIp);
    if (v?.isNotEmpty == true) {
      return v;
    } else {
      return "";
    }
  }

  String get proxy_port {
    final v = SpUtil.getString(_KProxyPort);
    if (v?.isNotEmpty == true) {
      return v;
    } else {
      return "";
    }
  }

  configProxyIp(String ip) {
    SpUtil.putString(_KProxyIp, ip);
  }

  configProxyPort(String port) {
    SpUtil.putString(_KProxyPort, port);
  }

  configDomain(String url) {
    SpUtil.putString(_KDomain, url);
  }

  configProxyEnable(bool enable) {
    SpUtil.putBool(_KProxyEnable, enable == true ? true : false);
  }

  api(String url) {
    return url;
  }

}

enum HBHttpMethod {
  get,
  post,
  delete,
  put,
}



















